In This Topic
Nevron Open Vision (NOV) provides support for the most common compression algorithms:
- bzip2 - a file compressor that uses the Burrows–Wheeler algorithm. Like gzip it is only a compressor for single files and not a full archiver. Bzip2 compresses most files more effectively than the older LZW (.Z) and Deflate (.zip and .gz) compression algorithms, but is considerably slower.
- gzip - a compression algorithm based on the Deflate algorithm, which is a combination of LZ77 and Huffman coding. Although its file format also allows for multiple compressed streams to be concatenated, gzip is normally used to compress just single files. Compressed archives are typically created by assembling collections of files into a single tar archive, and then compressing that archive with gzip. The final .tar.gz or .tgz file is usually called a tarball.
- zlib - an abstraction of the deflate algorithm used by the gzip compression. The zlib algorithm is very popular because of its great performance. It is used in many file formats such as ZIP, PNG, PDF, flash movies (SWF), etc. and is a crucial part of many platforms like Linux, Mac OS X, iOS, XBox, Playstation, Wii and so on.
- zip - the most popular archive file format. It compresses file streams individually and puts them in a single zip archive. As each file is compressed individually, the zip file format makes it easy and efficient to decompress only individual files instead of the whole file archive. Head to the Zip Compression topic for more information and code examples for compressing and decompressing zip archives.
The compression and decompression routines for the various compression algorithms are exposed through the NCompression static class. The source code below demonstrates how to compress and decompress a stream into the zlib format:
Zlib Compression and Decompression |
Copy Code
|
// Compress the input stream
NCompression.CompressZlib(inputStream, compressedStream, ENCompressionLevel.BestCompression);
// Decompress the compressed stream
NCompression.DecompressZlib(compressedStream, decompressedStream);
|
As the example above demonstrates, the compression method accepts as a parameter the compression level to apply. This is common for the zlib and the zip compression. The possible values are:
ENCompressionLevel |
Description |
NoCompression |
This level won't compress at all but output uncompressed blocks. |
BestSpeed |
The worst but fastest compression level. |
MediumCompression |
This level is a compromise between speed and compression ratio. |
BestCompression |
The best and slowest compression level. This tries to find very long and distant string repetitions. |
See Also